package com.oa.pojo;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class User implements Serializable{
    private String id;
    private String username;
    private String password;
    private String nickName;
    private String deptId;
    private String email;
    private String no;
    private String sex;
    private String createDate;

    private Dept dept;
    private Set<Role> roles;

    public User(String id, String username, Dept dept, Role role) {
        this.id = id;
        this.username = username;
        this.dept = dept;
        roles = new HashSet();
        roles.add(role);
    }

    public Role getRole() {
        if (roles != null) {
            return roles.iterator().next();
        }
        return null;
    }


    //功能: 获取主角色 [本系统暂时不做多角色, 这里先保留多角色特性]
    public Role getPrimaryRole() {
        if (roles != null) {
            Iterator<Role> it = roles.iterator();
            if (it.hasNext()) {
                return it.next();
            }
        }
        return null;
    }

    public User() {
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", nickName='" + nickName + '\'' +
                ", deptId='" + deptId + '\'' +
                ", email='" + email + '\'' +
                ", no='" + no + '\'' +
                ", sex='" + sex + '\'' +
                ", createDate='" + createDate + '\'' +
                ", dept=" + dept +
                ", roles=" + roles +
                '}';
    }
}